const gulp = require('gulp');
const htmlmin = require('gulp-htmlmin');
const fileinclude = require('gulp-file-include')
const gulpless = require('gulp-less')
const gulpcsso = require('gulp-csso')
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');

gulp.task('htmlmin',(cb)=>{
	console.log('first task');
	gulp.src('./src/index.html')
	.pipe(fileinclude())
	.pipe(htmlmin({collapseWhitespace: true}))
	.pipe(gulp.dest('dist'));
	cb();
});

gulp.task('cssmin',(cb)=>{
	console.log('first task');
	gulp.src(['./src/index.less'])
	.pipe(gulpless())
	.pipe(gulpcsso())
	.pipe(gulp.dest('dist'));
	cb();
});




gulp.task('copy', (cb) =>{

	gulp.src('./src/images/*')
	.pipe(gulp.dest('dist/images'))


	gulp.src('./src/font/*')
	.pipe(gulp.dest('dist/font'))
	gulp.src('./src/js/*')
	.pipe(gulp.dest('dist/js'))
	cb();
});
gulp.task('js', (cb) =>{
	gulp.src('./src/js/index.js')
	.pipe(babel({
		presets: ['@babel/preset-env']
	}))
	.pipe(uglify())
	.pipe(gulp.dest('dist/js'))
	cb();

});
gulp.task('default',gulp.series([
		'htmlmin',
		'cssmin',
		'js',
		'copy'
	]));